package day_2022_9_to_12.Day;

/**
 * @author haomin
 * @date 2022/09/05 22:24
 **/
public class Day3_6_Offer55_IsBalanced {
    class Solution {
        public boolean isBalanced(TreeNode root) {
            if(root == null) return true;
            int left = maxDepth(root.left);
            int right = maxDepth(root.right);
            if(Math.abs(left - right) > 1) return false;
            return isBalanced(root.left) && isBalanced(root.right);
        }
        private int maxDepth(TreeNode root){
            if(root == null) return 0;
            return 1 + Math.max(maxDepth(root.left), maxDepth(root.right));
        }
    }
}